package com.openatc.agent.model;

import com.openatc.model.model.AscsBaseModel;

/**
 * @author ：panleilei
 * @description
 * @modified By：
 * @version:
 * @date ：Created in 2024/10/24 10:43
 */
public class DeviceStatus {
    public static final String OFFLINE = "offline";
    public static final String ONLINE = "online";
    public static final String TOPIC = "DEVICE_STATUS";
    private String devGbId;    // 设备id，对应agentid
    private String devStatus;   // 设备状态 online-在线；offline-离线
    private long timestamp;     // 时间戳

    public String getDevGbId() {
        return devGbId;
    }

    public DeviceStatus(String devGbId, String devStatus, long timestamp) {
        this.devGbId = devGbId;
        this.devStatus = devStatus;
        this.timestamp = timestamp;
    }
    public DeviceStatus(String devGbId, String devStatus) {
        this(devGbId, devStatus, System.currentTimeMillis());
    }
    public static DeviceStatus convertDeviceStatus(AscsBaseModel device) {
        String agentId = device.getAgentid();
        String state = "UP".equals(device.getState()) ? ONLINE : OFFLINE;
        DeviceStatus status = new DeviceStatus(agentId, state, System.currentTimeMillis());
        return status;
    }

    @Override
    public String toString() {
        return "DeviceStatus{" +
                "devGbId='" + devGbId + '\'' +
                ", devStatus='" + devStatus + '\'' +
                ", timestamp=" + timestamp +
                '}';
    }
}
